+(function() {
  var Radiocheck = function(element, options) {
    this.init("radiocheck", element, options);
  };

  Radiocheck.DEFAULTS = {
    checkboxClass: "custom-checkbox",
    radioClass: "custom-radio",
    checkboxTemplate:
      '<span class="icons"><span class="icon-unchecked fa fa-times"></span><span span class="icon-checked fa fa-check" ></span></span>',
    radioTemplate:
      '<span class="icons"><span class="icon-unchecked fa fa-times"></span><span span class="icon-checked fa fa-check"></span></span>'
  };

  Radiocheck.prototype.init = function(type, element, options) {
    this.$element = $(element);/*element dom元素*/
    this.options = $.extend(
      {},
      Radiocheck.DEFAULTS,/* 默认值*/
      this.$element.data(),
      options
    );
    if (this.$element.attr("type") == "checkbox") {
      this.$element.addClass(this.options.checkboxClass);
      this.$element.after(this.options.checkboxTemplate);
    } else if (this.$element.attr("type") == "radio") {
      this.$element.addClass(this.options.radioClass);
      this.$element.after(this.options.radioTemplate);
    }
  };

  var Plugin = function(option) {
    return this.each(function() {
      var $this = $(this);
      //如果这个dom元素已经被初始化为radiocheck
      //data就会返回对象
      //如果没有被初始化
      //data返回空
      var data = $this.data("radiocheck");
      //如果我们纯进去的参数option的类型是object
      //options 赋值为 option
      //如果不是，options 赋值为false
      var options = typeof option == "object" && option;
      if (!data && option == "destory") {
        return;
      }
      if (!data) {
        $this.data("radiocheck", (data = new Radiocheck(this, options)));
      }
      if (typeof option == "scring") {
        data[option]();
      }
    });
  };

  var old = $.fn.radiocheck;

  /* fn=prototype 给jquery对象，添加一个函数*/
  $.fn.radiocheck = Plugin;
  $.fn.radiocheck.Constructor = Radiocheck;

  $.fn.radiocheck.noConflict = function() {
    $.fn.radiocheck = old;
    return this;
  };
})(this, jQuery);
